const obj = {
    name: '李四'
}
function test() {
    console.log(this, 'this')  //obj
}
test.apply(obj)

/**
 * cxt:{
 *    [Symbol('key)]:()=>{}
 * }
*/

Function.prototype.myApply = function (obj, args) {
    if (typeof this !== 'function') return new Error('调用对象必须是函数')
    const cxt = obj ?? globalThis
    const key = Symbol('key')
    cxt[key] = this
    const result = cxt[key](...args)
    delete cxt[key]
    return result
}

function test1(a = 1, b = 2) {
    console.log(a)
    console.log(this.a, this.b)
}
const obj1 = {
    a: 1,
    b: 2,
    // [Symbol('key')]: function test1(a = 1, b = 2) {
    //     console.log(a)
    //     console.log(this.a, this.b)
    // }
}
test1.myApply(obj1, ['abc'])